﻿using System.Collections.Generic;
using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.AddOrRemoveBuff, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_AddOrRemoveBuff : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.AddOrRemoveBuff;
        public override string name => LevelEditorConst.AddOrRemoveBuff;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.AddOrRemoveBuff, "buff目标"), Tooltip("1.玩家，2.所有队员，3.队长，4：实体")]
        public int hostType;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.AddOrRemoveBuff, "操作类型"), Tooltip("1.添加，2.移除")]
        public int opType;
        [Output("实体tag", false), VisibleIf(nameof(hostType), 4), Tooltip("仅参数1=4时有效")]
        public EditorLevelServiceTargetSetter tagOrMcid;

        [LevelServiceEditorCustomProperty(ServiceExecutionType.AddOrRemoveBuff, "LevelBuff表ID")]
        public List<int> buffs;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_AddOrRemoveBuff()
            {
                hostType = this.hostType,
                opType = this.opType,
                buffs = this.buffs,
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter
                ((x) => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_AddOrRemoveBuff rNode)
            {
                this.hostType = rNode.hostType;
                this.opType = rNode.opType;
                this.buffs = rNode.buffs;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_AddOrRemoveBuff rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid, nameof(tagOrMcid));
            }
        }
    }
}